<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>Vue初探——全局构建版本</title>
        <link rel="stylesheet" href="common.css">
        <script src="https://lib.baomitu.com/vue/latest/vue.global.js"></script>
    </head>
    <body>
        <div id="app">
            <p>{{ message }}</p>
            <p>
                <my-counter></my-counter>
                <my-counter></my-counter>
            </p>
        </div>
        <script>
            const { createApp } = Vue;
            let app = createApp({
                data() {
                    return {
                        message: "组件基础实例",
                    };
                },
            });

            app.component("MyCounter",{
                template: `
                <button @click="add">已点击 {{ counter }} 次</button>
                `,
                data() {
                    return {
                        counter:0,
                    };
                },
                methods: {
                    add() {
                        this.counter++;
                    }
                },
                mounted() {
                    console.log("组件MyCounter挂载");
                }
            });

            app.mount('#app');
        </script>
    </body>
</html>